package cn.zhaoyuening.crm.web.action;

import java.io.IOException;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.zhaoyuening.crm.domain.CrmPost;
import cn.zhaoyuening.crm.service.PostService;
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

public class PostAction extends BaseAction<CrmPost> {
	private PostService postService;
	private CrmPost post = new CrmPost();
	
	//ajax 二级联动 department->post
	public String showPostByDepartment() throws IOException{
		//获取该部门所有post
		List<CrmPost> list = postService.findAll(post.getCrmDepartment());
		//转换为json数据
		JsonConfig jsonConfig = new JsonConfig();
		//设置排除的元素
		//避免死循环
		jsonConfig.setExcludes(new String[]{"crmDepartment","crmStaffs"});
		String jsonInfo = JSONArray.fromObject(list, jsonConfig).toString();
		//发送数据
		ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
		ServletActionContext.getResponse().getWriter().print(jsonInfo);
		return NONE;
	}
	
	public void setPostService(PostService postService) {
		this.postService = postService;
	}

	public CrmPost getPost() {
		return post;
	}
	
	public void setPost(CrmPost post) {
		this.post = post;
	}
	

}
